<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="/resource/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>${title}</title>
		<script type="text/javascript">
		$(function(){
			$("body").css({visibility:"visible"});
			
		})
		function submitForm(){
				
				
				
				if($("#query_form").form('validate'))
				{
					if(checkcode()){
					//$("#parentName").val($("#parentId option:selected").text());
					top.mask();
					$("#query_form").ajaxSubmit({
						type:"post",
						dataType:"json",
						success:function(data){
							if(data.result == "1"){
								top.showMsg("名称不能重复");
								window.setTimeout(function(){
								$("#name").focus();
								top.unmask();
								},1500);
							}else{
								top.showMsg("保存成功");
								window.setTimeout(function(){
								top.unmask();
								top.refresh('afterSave');
								},1500);
							}
						},
						error:function(){
							alert();
							top.showMsg("错误");
							window.setTimeout(function(){
								top.unmask();
								},1000);
						}
					});
				}
					}
				
				
				
				
			}
			
			
			function checkcode(){
				var parentid = $("input[name='parentId']").val();
				var code = $("#code").val();
				var isok;
				//输入code时判断是否符合规定
				if(code.length>0){
				top.mask();
				var url = parent.formateUrl("dictionary/checkcode/@/#.json".replace("@", parentid).replace("#", code));
				$.ajax({
				type : "post",
				dataType : "json",
				async: false,//同步，不使用异步
				url : url,
				success : function(data) {
						if(data.result){
							top.unmask();
							isok= true;
						}else{
							if('${dict.code }'== $("#code").val()){
								isok= true;
							}else{
							top.showMsg("该编码已经存在，请重新输入！");
							window.setTimeout(function(){
								$("#code").focus();
								top.unmask();
								isok= false;
							},1500);	
							}
						}
					},
					error : function() {
						top.showMsg("出错,请联系管理员");
						window.setTimeout(function(){
								top.unmask();
								isok= true;
							},1500);
					}
				});
				}else{
					isok= true;
				}
				return isok;
			}
			
		</script>
	</head>


	<body >
		<form style="margin: 0;padding: 0;" method="post" id="query_form" action="<c:url value='/dictionary/edit.json'/>">
			<table>
				<tr>
					<td class="td_label">字典项:</td>
					<td>
						<input type="text" name="parentName" value='${dict.parentName}' id="parentName" readonly="readonly" style="width:254px;"/>
						<input type="hidden" name="parentId" value="${dict.parentId}">
					</td>
				</tr>
				<tr>
					<td class="td_label">字典值:</td>
					<td >
						<input class="easyui-validatebox" data-options='required:true,tipPosition:"bottom",missingMessage:"请输入字典值"'  style="width:254px;" maxlength="25" type="text" value="${dict.name }" id="name" name="name" />
					</td>
				</tr>
				<tr>
					<td class="td_label">编码:</td>
					<td >
						<input style="width:254px;" maxlength="2" type="text" id="code" name="code" value="${dict.code }"/>
					</td>
				</tr>
				<tr>
					<td class="td_label">排序序号:</td>
					<td >
						<input class="easyui-numberbox" data-options='required:true,tipPosition:"bottom",missingMessage:"请输入数字"' style="width:254px;" type="text"  value="${dict.orderNum }" id="orderNum" name="orderNum"/>
						<input type="hidden" value="${dict.dbId }" name="dbId" />
					</td>
				</tr>
				<tr>
					<td class="td_label">备注:</td>
					<td >
						<input style="width:254px;" maxlength="80" value="${dict.remark }" type="text" id="remark" name="remark"/>
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>